#!/bin/sh
#
#   Copyright (C) 1998 TakeFive Software Software GmbH.
#
# Author: Toni Leherbauer <toni@takeFive.co.at>
# Maintainer: Toni Leherbauer <toni@takeFive.co.at>
# Created: 1998/04/20
# Keywords: tools sniff
#
# Commentary:
# 	SNiFF+ - ClearCase trigger script
# 	for automatic update of symbol information
#
# Usage:
#	sniff_ClearCase_notify.sh   log_file_name [max_no_of_lines]
#

if [ -z "$1" ]; then
    echo "`basename $0`: No log file name specified"
    exit 1
fi

cifile=$CLEARCASE_PN
curdate=`date +"%Y/%m/%d"`
curtime=`date +"%T"` 
entry="$curdate $curtime $cifile"

test $DEBUG && echo $entry

while [ -f $1.lck ];
do
	sleep 1
done

touch $1.lck
echo $entry >> $1

maxlines=$2
if [ -n "$maxlines" ]; then 
	lines=`cat $1 | wc -l`
	if [ $lines -gt $maxlines ]; then
		tail +`expr $lines - $maxlines` $1 
	fi
	cat $1 | sed -e "\*$curdate*!d" > $1.new
	mv $1.new $1
fi

rm -f $1.lck
